import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '../views/login/index.vue'
// 导入路由-方式1-直接导入
// import Layout from '@/views/layout/index.vue'

Vue.use(VueRouter)
const routes = [
  // 首页
  // { path: '/', component: Layout },
  // 导入路由-方式2-懒加载导入
  // 当访问页面的时候,再去加载模块,提高性能
  {
    path: '/',
    component: () => import('@/views/layout/index.vue'),
    meta: { keepAlive: true },
    redirect: '/home',
    children: [
      { path: 'home', component: () => import('@/views/home/index.vue'), meta: { keepAlive: true } },
      { path: 'video', component: () => import('@/views/video/index.vue') },
      { path: 'my', component: () => import('@/views/my/index.vue') },
      { path: 'qa', component: () => import('@/views/qa/index.vue') }
    ]
  },
  // 登录页面
  { path: '/login', component: Login },
  // 搜索页面
  { path: '/search', component: () => import('@/views/search/index.vue') },
  // 通过props: true,页面可以通过props进行接受路由传参
  { name: 'article', path: '/article/:articleId', component: () => import('@/views/article/index.vue'), props: true },
  // 修改用户资料
  { path: '/user', component: () => import('@/views/user/index.vue') }
]

const router = new VueRouter({
  routes
})

export default router
